import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import postcssImport from "postcss-import"
import autoprefixer from "autoprefixer"
import tailwindcss from "tailwindcss"
import path from "path"

// https://vitejs.dev/config/
export default defineConfig({
    build: {
        outDir: "dist",
        assetsDir: "static",
        publicPath: "./",
        rollupOptions: {
            output: {
                // https://rollupjs.org/guide/en/#outputmanualchunks
                manualChunks: {
                    vlib: ["vue", "vue-router", "vuex"],
                    "element-plus": ["element-plus"],
                },
            },
        },
    },
    autoOpenBrowser: true,
    server: {
        proxy: {
            "/api": {
                target: "http://jsonplaceholder.typicode.com",
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ""),
            },
        },
    },
    css: {
        postcss: {
            plugins: [autoprefixer, postcssImport, tailwindcss],
        },
    },
    plugins: [vue()],
    resolve: {
        alias: [{ find: "@", replacement: path.resolve(__dirname, "src") }],
    },
})
